﻿#if WINDOWS
using System.Windows.Input;

#else
using Avalonia.Controls;
using Avalonia.Input;

#endif

namespace KinonekoSoftware.Foundation.UI.ViewModels
{
    public abstract class ShellCore : ViewModelBase, IBusyServiceEX
    {
        #region Keyboard Routing

        internal void KeyDown(KeyEventArgs e)
        {
            int modifiers;
            int key;

#if WINDOWS
            modifiers = (int)e.KeyboardDevice.Modifiers;
            key = (int)e.Key;

#else
            modifiers = (int)e.KeyModifiers;
            key       = (int)e.Key;


#endif

            e.Handled = OnKeyboardRouting(key, modifiers, false);
        }

        internal void KeyUp(KeyEventArgs e)
        {

            int modifiers;
            int key;

#if WINDOWS
            modifiers = (int)e.KeyboardDevice.Modifiers;
            key = (int)e.Key;

#else
            modifiers = (int)e.KeyModifiers;
            key       = (int)e.Key;


#endif

            e.Handled = OnKeyboardRouting(key, modifiers, true);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="modifier"></param>
        /// <param name="isUp"></param>
        /// <returns>如果不希望控件继续处理键盘事件，则返回true，否则返回false</returns>
        protected virtual bool OnKeyboardRouting(int key, int modifier, bool isUp)
        {
            return false;
        }

        #endregion

        #region DragDrop Routing

        internal void Drag()
        {

        }

        #endregion


        #region IBusyService

        public Task Await(int                           t = 1) => Ioc.Get<IBusyServiceEX>().Await(t);
        public void Update(string                       text) => Ioc.Get<IBusyServiceEX>().Update(text);
        public Task<IBusyServiceEX> BeginSession(string text) => Ioc.Get<IBusyServiceEX>().BeginSession(text);

        #endregion
    }
}